using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace LANLauncher
{
	internal static class Program
	{
		[STAThread]
		private static void Main(string[] args)
		{
			using (Mutex mutex = new Mutex(false, string.Concat("Global\\", "{BB70E2F6-D6D4-4bc2-AC34-E63D84FE43E7}")))
			{
				if (mutex.WaitOne(0, false))
				{
					if ((int)args.Length > 1)
					{
						if (args[0] == "-AdminLaunchGame")
						{
							string str = "";
							RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Rockstar Games\\L.A. Noire") ?? Registry.LocalMachine.OpenSubKey("Software\\Rockstar Games\\L.A. Noire");
							if (registryKey != null)
							{
								object value = registryKey.GetValue("InstallDir");
								if (value != null)
								{
									str = value.ToString();
								}
							}
							if (str != "")
							{
								int num = int.Parse(args[1]);
								Process processById = Process.GetProcessById(num);
								if (processById != null)
								{
									processById.WaitForExit();
								}
								ProcessStartInfo processStartInfo = new ProcessStartInfo()
								{
									UseShellExecute = true,
									FileName = string.Concat(str, "\\LANoire.exe"),
									WorkingDirectory = str,
									Verb = "runas",
									Arguments = ""
								};
								try
								{
									Process.Start(processStartInfo);
									Application.EnableVisualStyles();
									Application.SetCompatibleTextRenderingDefault(false);
									Application.Run(new SplashScreen("Restarting L.A. Online with Administrator rights..."));
								}
								catch (Exception exception)
								{
								}
								return;
							}
							else
							{
								return;
							}
						}
						else if (args[0] == "-SplashScreen")
						{
							Application.EnableVisualStyles();
							Application.SetCompatibleTextRenderingDefault(false);
							Application.Run(new SplashScreen(args[1]));
							return;
						}
						else if (args[0] == "-PatchArbitrate")
						{
							string str1 = args[1];
							ProcessStartInfo processStartInfo1 = new ProcessStartInfo()
							{
								FileName = "ypatcher.exe",
								UseShellExecute = true,
								Verb = "runas",
								Arguments = string.Concat("-finalize -waitforprocess ", str1)
							};
							Process.Start(processStartInfo1).WaitForExit();
							ProcessStartInfo processStartInfo2 = new ProcessStartInfo()
							{
								FileName = "LANoire.exe"
							};
							Process.Start(processStartInfo2);
							Application.EnableVisualStyles();
							Application.SetCompatibleTextRenderingDefault(false);
							Application.Run(new SplashScreen("Restarting L.A. Online"));
							return;
						}
					}
					Application.EnableVisualStyles();
					Application.SetCompatibleTextRenderingDefault(false);
					Application.Run(new LauncherForm());
				}
			}
		}
	}
}